/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.U.
 */
package es.silenus.detecta.task;

import java.io.Serializable;

import java.util.HashMap;
import java.util.Map;


/**
 * Abstract task.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 25-ago-2009 17:34:55
 */
public abstract class AbstractTask implements Task, Serializable {
	/**
	 * Thread local parameters.
	 */
	private static final ThreadLocal<Map<String, Object>> PARAMS = new ThreadLocal<Map<String, Object>>() {
			protected Map<String, Object> initialValue() {
				return new HashMap<String, Object>();
			}
		};

	/**
	 * Sets task parameters.
	 *
	 * @param parameters task parameters.
	 */
	public final void setParameters(final Map<String, Object> parameters) {
		PARAMS.set(parameters);
	}

	/**
	 * The execute method.
	 */
	public final void execute() {
		executeInternal();
	}

	/**
	 * Retrieves the parameters
	 *
	 * @return the parameters.
	 */
	protected final Map<String, Object> getParameters() {
		return PARAMS.get();
	}

	/**
	 * Executes the task.
	 */
	protected abstract void executeInternal();
}
